package com.example.controller;

import com.example.domain.Score;
import com.example.service.ScoreService;
import com.example.util.EasyuiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/score")
@Slf4j
public class ScoreController {
    
    @Autowired
    private ScoreService scoreService;
    
    /**
     * 查询所有学生成绩,并分页
     *
     * @param page     页码,从1开始,后端从0开始
     * @param rows     每页的条数
     * @param sort     需要排序的列
     * @param order    排序的方向
     * @param clazzid  班级id,可以通过clazzid来获取这个班级的所有人
     * @param courseid 课程id,通过courseid查询课程
     * @return Easyui中datagrid的数据结构, row和data
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public EasyuiResult<Score> list(@RequestParam(name = "page", defaultValue = "1", required = false) int page,
                                    @RequestParam(name = "rows", defaultValue = "10", required = false) int rows,
                                    @RequestParam(name = "sort", defaultValue = "id", required = false) String sort,
                                    @RequestParam(name = "order", defaultValue = "DESC", required = false) String order,
                                    @RequestParam(name = "clazzid", defaultValue = "0", required = false) int clazzid,
                                    @RequestParam(name = "courseid", defaultValue = "0", required = false) int courseid
    ) {
        log.info("课程列表,参数为 page={},row={},sort={},order={},clazzid={},courseid={}",
                page, rows, sort, order, clazzid, courseid);
        // int nowPage = 0;
        // if (page > 0)
        //     nowPage = page - 1;
        
        return scoreService.list(page - 1, rows, sort, order, clazzid, courseid);
    }
}
